const fs = require('fs')
const vm = require('vm')

function Modules() {
  this.exports = {}
}

Modules.prototype._compile = function (file) {
  const source = fs.readFileSync(file)
  const src = `;(function(modules) {\n${source}\nreturn modules\n})`
  const fn = vm.runInThisContext(src)
  return fn  
}

function _require(file) {
  const modules = new Modules()
  const fn = modules._compile(file)
  return fn(modules).exports
}


const add = _require('./add.js')
console.log(add)
console.log(add(1, 3))
